Across the embedded and non-embedded CPU market, one finds predominant Instruction Set Architectures (ISAs) for which large bodies of software exist that could be “accelerated” for performance, or “translated” to a myriad of capable processors that could present better cost/performance benefits, provided they could transparently access the relevant software. One also finds dominant CPU architectures that are locked in time to their ISA, and cannot evolve in performance or market reach and would benefit from “synthetic CPU” co-architecture.
It is often desired to run program code written for a computer processor of a first type (a “subject” processor) on a processor of a second type (a “target” processor). Here, an emulator or translator is used to perform program code conversion, such that the subject program is able to run on the target processor. PCT application WO00/22521 discloses program code conversion methods and apparatus to facilitate such acceleration, translation and co-architecture capabilities as may be employed in embodiments of the present invention.
A subject program to be translated usually consists of multiple units of subject code, including the subject application and a number of subject libraries, some of which may be proprietary and some of which are provided as part of the subject OS (“system libraries”). As the subject program runs, control flow passes between these different units of subject code as function calls are made to the libraries.
In certain operating systems, for example Solaris from Sun Microsystems Inc., the process of linking function calls to library code which implement the function can be performed at run time, and this procedure is known as dynamic linking. Dynamic linking is performed by dynamic linker code, and involves the use of an intermediate control structure known as a Procedure Linkage Table (PLT).
The PLT is part of a compiled program, and contains an entry including link information for each library function required by the program. When a first call to a library function is encountered in a typical run of the program, control flow jumps to the PLT entry associated with that function. The PLT entry for that function controls the linking process at this stage by invoking the dynamic linker code. The dynamic linker code causes the link information for the function in question to be updated. By updating the link information, the dynamic linker code makes a link from the PLT entry for that function to the library code for implementing the function. The link established in this way typically persists for the remainder of the run of the program.
The dynamic linker code can then pass control flow to the code in the library so that the function is executed.
Subsequent invocations of the function by the program pass control flow as before to the PLT entry. Since the PLT entry has been updated with a link to the library code which implements the function, the PLT now causes control flow to pass directly from there to the library in these subsequent invocations. These subsequent invocations require neither a further update of the PLT entry, nor a further invocation of the dynamic linker.
In certain operating systems, the action of creating a link between the PLT entry for a function and the library containing the code for performing the function has the effect of modifying data associated with the PLT, such as a global offset table. The modified global offset table can then be read at run-time by the code in the PLT entry, enabling formation of a link. In certain other operating systems, for example Solaris, the action of creating the link between the PLT entry for a certain function and the library including that function has the alternative effect of modifying the executable code which forms the PLT entry itself.
The use of the PLT as an intermediate control structure as described above, in particular the modification of link information in the PLT by modifying the code comprising the PLT the first time that a function is called, complicates program code conversion for subject code employing a PLT as part of a dynamic linking mechanism.
Code modification at run-time presents problems to dynamic translators, since subject code that is modified may correspond to target code which has already been translated. When such a modification of the subject code occurs, all target code translations of the modified subject code must be identified and discarded as stale. Thus, the translator should be able to identify all target code sequences (i.e., translations) that correspond to particular subject code addresses being modified.
In dynamic translators, finding and deleting the target code which corresponds to a given subject address is difficult and sometimes not even possible. In some situations, optimizations are applied during translation which yield translations that can no longer be exactly correlated to the range of subject addresses that the translations represent. In these situations, if the subject program modifies its own code at certain subject address, the translator has no way to identify which respective translated target code to invalidate. In addition, safe deletion of translated target code in a multi-threaded environment may pose further problems.
Techniques to deal with code modification have been described in PCT application WO05/008487. Although these techniques are useful, the inventors have now identified that the high concentration of code modification which occurs in a PLT at run-time may make the techniques as described in PCT WO05/008487 an inefficient way of dealing with PLT updates. Such techniques can ensure that no invalid translated target code is executed, however, management of control flow when dealing with PLT updates using these techniques has been found to be expensive in terms of processor and memory resources.
Furthermore, the inventors have now identified that the PLT updating method used by the dynamic linker ld.so in the Solaris operating system notably increases the number of partitions needed to execute a typical dynamically linked program, compared to dynamic linkers in some other operating systems.
A method of handling dynamically linked function calls with respect to translation of subject program code is provided, along with a computer apparatus to take advantage of the handling method. Preferred embodiments enable a link to be established from a function call in subject code to code corresponding to the subject code function using a function linkage table, without generating target code corresponding to the intermediate control structure. A computer apparatus including a translator operating to convert subject code to target code can be arranged such that dynamically linked function calls in the subject program are identified, and target code is generated which features a direct association with code for performing the function, that association based on information gathered by the translator into a function linkage table.
Preferred embodiments of the technique for handling dynamically linked function calls enable dynamically linked function calls in subject code to be conveniently associated with code for performing the function. Preferred embodiments may reduce processing and memory overheads associated with techniques such as those known from PCT WO05/008487 for dealing with code modification.
The present invention can thereby improve performance of a computer system, e.g. while undertaking program code conversion.